const path = require("path")

const isDev = process.env.NODE_ENV === "development"
const stylePath = "./src/assets/styles/*.less"

module.exports = {
    publicPath: "./",

    css: {
        loaderOptions: {
            css: {
                localIdentName: isDev ? "[local]-[hash:3]" : "[hash:10]",
                camelCase: "only"
            }
        }
    },

    chainWebpack: config => {
        const types = ["vue-modules", "vue", "normal-modules", "normal"]
        types.forEach(type => addStyleResource(config.module.rule("less").oneOf(type)))
    },

    productionSourceMap: false
}

function addStyleResource(rule) {
    rule.use("style-resource")
        .loader("style-resources-loader")
        .options({
            patterns: [path.resolve(__dirname, stylePath)]
        })
}
